package com.helloandroid.activesitting.bl;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.helloandroid.activesitting.ApplicationObject;
import com.helloandroid.activesitting.R;

public class NotificationActiveSittingManager {

	private static final int ID_CURRENT = 123;
	private static final int ID_ONGOING = 111;

	public static void ShowCurrentNotification(int picture) {
		Notification notification = new Notification(picture,
				"It's time to move!", System.currentTimeMillis());
		Intent notificationIntent = new Intent(ApplicationObject.ApplicationContext,AlarmReceiver.class);
		notificationIntent.setAction(AlarmReceiver.ACTION_REACT_TO_NOTIFICATION);

		PendingIntent intent = PendingIntent.getBroadcast(
				ApplicationObject.ApplicationContext, 0, notificationIntent,
				android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
		notification.setLatestEventInfo(ApplicationObject.ApplicationContext,
				"It's time to move!", "", intent);

		notification.flags|=Notification.FLAG_AUTO_CANCEL;
		android.app.NotificationManager notificationManager = (android.app.NotificationManager) ApplicationObject.ApplicationContext
				.getSystemService(Context.NOTIFICATION_SERVICE);
		notificationManager.notify(ID_CURRENT, notification);

	}
	
	

	public static void ShowOnGoingNotification(String nextTime) {
		Notification notification = new Notification(R.drawable.ic_launcher,
				"", System.currentTimeMillis());
		Intent notificationIntent = new Intent();

		PendingIntent intent = PendingIntent.getActivity(
				ApplicationObject.ApplicationContext, 0, notificationIntent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		notification.setLatestEventInfo(ApplicationObject.ApplicationContext,
				"The next break:", nextTime, intent);

		notification.flags|= Notification.FLAG_ONGOING_EVENT;
		android.app.NotificationManager notificationManager = (android.app.NotificationManager) ApplicationObject.ApplicationContext
				.getSystemService(Context.NOTIFICATION_SERVICE);
		notificationManager.notify(ID_ONGOING, notification);
		
		
	}
	
	public static void removeOnGoingNotification(){
		android.app.NotificationManager notificationManager = (android.app.NotificationManager) ApplicationObject.ApplicationContext
				.getSystemService(Context.NOTIFICATION_SERVICE);
		
		notificationManager.cancel(ID_ONGOING);
	
	}
	
	public static void removeCurrentNotification(){
		android.app.NotificationManager notificationManager = (android.app.NotificationManager) ApplicationObject.ApplicationContext
				.getSystemService(Context.NOTIFICATION_SERVICE);
		
		notificationManager.cancel(ID_CURRENT);
	
	}
	
}
